package main

import (
	"github.com/labstack/echo/v4"
	"github.com/labstack/echo/v4/middleware"
	echoSwagger "github.com/swaggo/echo-swagger"
	global2 "longmen/server/config/global"
	_ "longmen/server/docs"
	"longmen/server/internal/api"
	"longmen/server/pkg/common/helper/const"
	middlewares2 "longmen/server/pkg/common/middlewares"
	"longmen/server/pkg/common/services"
	"longmen/server/pkg/grpc_client"
)

func main() {
	global2.Initialize("../../../config/app.properties")
	e := echo.New()
	if _const.SwagIsEnable {
		e.GET("/swagger/*", echoSwagger.WrapHandler)
	}
	e.Debug = true
	service := &services.Service{global2.GetX()}
	base := api.Controller{
		Service: service,
	}
	reqBodyFunc := middlewares2.ReqBodyWithConfig(middlewares2.ReqBodyConfig{})
	/*authFunc := middlewares.BasicAuthWithConfig(middlewares.BasicAuthConfig{
		BasicAuthSkipper: middleware.DefaultSkipper,
		Service:          service,
	})*/
	middlewares2.InitSkipVerifyFunc()
	e.Use(reqBodyFunc,
		middleware.CORSWithConfig(middleware.DefaultCORSConfig),
		middleware.RecoverWithConfig(middleware.RecoverConfig{
			StackSize: 1 << 10, //1kb
		}))
	groups := make([]*echo.Group, 0)
	groups = append(groups, e.Group("/api"))
	for idx := range groups {
		//腾讯IM
		tencentIm := groups[idx].Group("/tencentIm")
		{
			// IM回調接口
			tencentIm.POST("/callback", base.Callback)
		}
	}
	grpc_client.InitTimGrpc()
	e.Logger.Fatal(e.Start(":" + global2.Config.GetString("sys.call_back_port")))
}
